<?php
header("content-type:text/html;charset=utf8");
$user = $_GET['user'];
$remove = $_GET['remove'];
$name = $_GET['name'];
$con = mysqli_connect('localhost', 'root', 'root', 'userdata');
mysqli_query($con, 'set names utf8');
if (!$remove) {
    $res = mysqli_query($con, "select * from goods where user='$user'");
    $data = [];
    while ($row = mysqli_fetch_assoc($res)) {
        $data[] = $row;
    }
    if ($data) {
        $arr = [
            "meta" => [
                "status" => 1,
                "msg" => "获取成功",
                "data" => $data,
            ]
        ];
    } else {
        $arr = [
            "meta" => [
                "status" => 0,
                "msg" => "购物车列表为空",
                "data" => "null",
            ]
        ];
    }
    echo json_encode($arr);
} else {
    $res = mysqli_query($con, "delete from goods where user='$user' and name='$name'");
    if ($res) {
        $arr = [
            "meta" => [
                "status" => 1,
                "msg" => "删除成功"
            ]
        ];
    } else {
        $arr = [
            "meta" => [
                "status" => 2,
                "msg" => "删除失败"
            ]
        ];
    }
    echo json_encode($arr);
}


